package dao

import (
	"TTMS/model"
	"TTMS/utils"
)

// AddHall 添加演出厅
func AddHall(row, col int64) error {
	//写 sql 语句
	sqlStr := "insert into halls(seat_num, row_num, col_num, remain_num) values (?,?,?,?)"
	hall := &model.Hall{
		RowNum: row,
		ColNum: col,
	}
	hall.SeatNum = hall.GetSeatNum()
	hall.RemainNum = hall.SeatNum
	//执行
	_, err := utils.DB.Exec(sqlStr, hall.SeatNum, row, col, hall.RemainNum)
	if err != nil {
		return err
	}
	return nil
}

// GetHallByID 根据演出厅id获取演出厅
func GetHallByID(hallID int64) *model.Hall {
	//写 sql 语句
	sqlStr := "select id,seat_num, row_num, col_num, remain_num from halls where id=?"
	//执行
	row := utils.DB.QueryRow(sqlStr, hallID)
	hall := &model.Hall{}
	row.Scan(&hall.ID, &hall.SeatNum, &hall.RowNum, &hall.ColNum, &hall.RemainNum)
	return hall
}
